package com.genesis.yunnanji.view.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.flyco.tablayout.SlidingTabLayout;

import com.genesis.yunnanji.R;
import com.genesis.yunnanji.adapter.ClassifySortAdapter;
import com.genesis.yunnanji.widget.NoScrollViewPager;
import com.youth.xframe.widget.XToast;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;
import butterknife.Unbinder;

/**
 * 创建日期：2018/9/19 on 17:30
 * 作者:Kite
 * 描述:分类
 */
public class ClassifyFragment extends BaseFragment {

    @BindView(R.id.vp_content)
    NoScrollViewPager vpContent;

    @BindView(R.id.tabs)
    SlidingTabLayout tabs;

    @BindView(R.id.actionbar_back)
    ImageView actionbarBack;

    @BindView(R.id.actionbar_title)
    TextView actionbarTitle;

    Unbinder unbinder;

    private ArrayList<String> functionList = new ArrayList<>();

    private List<Fragment> fragmentList = new ArrayList<>();

    /**
     * Fragment 实例
     */
    public static ClassifyFragment newInstance(Object... pramars) {
        ClassifyFragment fragment = new ClassifyFragment();
        fragment.setArguments(getBundle(pramars));
        return fragment;
    }

    @Override
    public View initView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_classify, container, false);
        return view;
    }

    @Override
    public void initData(Bundle savedInstanceState) {
        super.initData(savedInstanceState);
        actionbarBack.setImageResource(R.drawable.home_search);
        actionbarTitle.setText("全部分类");
        intFragment();
    }

    private void intFragment() {
        functionList.add("分类");
        functionList.add("品牌");
        fragmentList.add(ClassifyChildFragment.newInstance());
        fragmentList.add(ClassifyBrandFragment.newInstance());
        ClassifySortAdapter fragmentAdapter = new ClassifySortAdapter(getChildFragmentManager(), fragmentList, functionList);
        vpContent.setAdapter(fragmentAdapter);
        vpContent.setOffscreenPageLimit(2);
        vpContent.setCurrentItem(0);
        tabs.setViewPager(vpContent);
    }

    @OnClick(R.id.actionbar_back)
    public void onViewClicked() {
        XToast.info("点你妹呀");
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }
}
